package common;

import java.net.InetAddress;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import utils.StringUtil;


public class Bram {
	
	private final static Long TIMEOUT=1000L;  

	public static boolean isIp(String ip) { 
		
		final ExecutorService exec = Executors.newFixedThreadPool(1);  
	    Callable<String> call = new Callable<String>() {  
	        public String call() throws Exception {  
	            return  InetAddress.getByName(ip).getHostName();
	        }  
	    };  
	    try {  
	        Future<String> future = exec.submit(call);  
	        String result = future.get(TIMEOUT, TimeUnit.MILLISECONDS);   
	        if (!StringUtil.isEmpty(result)&&result.indexOf("amazonaws") > 0) {
				return true;
			}
	    } catch (Exception e) {  
	    	return false;
	    }  
	    exec.shutdown();  
	    return false;  
	}

	public static boolean isBram(String ip) {
		if (isIp(ip)) { 
			return true;
		} else {
			return false;  
		}
	}
	
	
}
